package events;

import java.util.Random;

import simulation.Echeancier;
import simulation.StationState;


public class BackToStation extends Event {
	
	private int provenance;
	
	public BackToStation(int provenance){
		super();
		this.provenance = provenance;
	}

	@Override
	public String toString() {
		return "Un skieur arrive en bas des pistes [T="+Echeancier.toHour(date)+"]"; 
	}

	@Override
	public void treat(Echeancier e) {
		
		switch (provenance) {
			case 1: StationState.p1--;break;
			case 2: StationState.p2B--;break;
			case 3: StationState.p3--;break;
			default: StationState.p4--;break;
		}
		
		Event next;
		int rand = (new Random()).nextInt(20);
		if (rand==0 ||  date >= Echeancier.T17H){
			//Le skieur quitte la station
			next = new GoodByeEvent();
			next.date = date;
		}else {
			rand = (new Random()).nextInt(10);
			if (rand==0){
				//Le skieur remonte par D
				next = new EndWaitTeleSkiD();
				next.date = 10+date+(10*StationState.WD);
				StationState.WD++;
			}
			else{
				if(StationState.WB <= StationState.WC){
					next = new EndWaitTeleSkiB();
					next.date = 10+date+(10*StationState.WB);
					StationState.WB++;
				}else{
					next = new EndWaitTeleSkiC();
					next.date = 10+date+(10*StationState.WC);
					StationState.WC++;
				}
			}
			
		}
		e.ajouter(next);

		
	}

	
	
}
